package com.tange.module.device.info.switcher;

import android.text.TextUtils;

import com.tange.core.backend.service.response.RxResponse;
import com.tange.module.device.info.DeviceInfoServiceManager;
import com.tange.module.device.info.RxServiceQueryCallback;
import com.tg.appcommon.android.TGLog;
import com.tg.data.http.entity.NotifyDataBean;
import com.tg.network.socket.http.TGHttp;

import java.util.HashMap;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 设备告警消息开关状态查询
 */
public class DeviceAlarmSwitcherQueryServiceImpl implements DeviceAlarmSwitcherQueryService {

    private static final String TAG = DeviceInfoServiceManager.TAG + "AlarmSwitcher";

    @Override
    public Observable<RxResponse<NotifyDataBean>> query(String uuid) {

        return Observable.create(emitter -> {

            if (emitter == null || emitter.isDisposed()) {
                TGLog.i(TAG, "[query] emitter invalid");
                return;
            }

            if (TextUtils.isEmpty(uuid)) {
                emitter.onNext(RxResponse.createFailed("uuid empty"));
                return;
            }

            final HashMap map = new HashMap();
            map.put("uuid", uuid);

            TGLog.i(TAG, "[query] params = " + map);

            TGHttp.getInstance().getAlarmMsgSwitcher(map)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new RxServiceQueryCallback(emitter));
        });
    }
}
